
import React from 'react';
import * as THREE from 'three';
import { Card, Form, InputNumber } from "antd";
import { useElement } from "tools/hooks/useElement";
import { useProperty } from 'tools/hooks/useProperty';


/**
 * 点光源
 * 从一个点向各个方向发射的光源。一个常见的例子是模拟一个灯泡发出的光。
 **/
export default function PointLightCard() {

    const { element } = useElement();

    const light = React.useMemo<THREE.Light | undefined>(() => {
        if (!element) return undefined
        if (element.type === 'light') {
            return element.object3D as THREE.Light;
        }
    }, [element])

    const pointLight = React.useMemo<THREE.PointLight | undefined>(() => {
        if (light instanceof THREE.PointLight) {
            return light
        } else {
            return undefined;
        }
    }, [light])

    const { setProperty } = useProperty(pointLight)

    if (!pointLight) return <></>;
    return (
        <Card title="点光源">
            <Form
                layout="horizontal"
                labelCol={{ span: 9 }}
                wrapperCol={{ span: 15 }}
            >
                <Form.Item label='光功率' tooltip='表示以"流明（光通量单位）"为单位的光功率'>
                    <InputNumber
                        bordered={false}
                        size='small'
                        style={{ width: '100%' }}
                        value={pointLight.power}
                        onChange={setProperty('power')}
                    />
                </Form.Item>
            </Form>
        </Card>
    )
}